package correct.day26;

import java.util.Arrays;
import java.util.Scanner;

public class Test3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), p = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        Arrays.sort(arr);

        String s = "ss";
        StringBuilder sb = new StringBuilder(s);
        sb.append(s);

        int left = 0, right = 0, ret = 0;
        p *= 2;
        while (right < n) {
            while (arr[right] - arr[left] > p) {
                left++;
            }
            ret = Math.max(ret, right - left + 1);
            right++;
        }
        System.out.println(ret);
    }
}
